﻿package net.wangit.adm.role;

import net.wangit.Unit;
import net.wangit.context.ActionContext;
import net.wangit.support.UnitInterceptor;
import net.wangit.user.role.Role;
import net.wangit.user.role.RoleFactory;
import net.wangit.util.Checker;
import net.wangit.view.unit.UnitComponent;

public class RoleRelationUI implements UnitInterceptor {

	public RoleRelationUI() {
	}

	public String intercept(ActionContext ac, Unit unit) throws Exception {
		String roleId = ac.getRequestParameter("roleid");
		if (Checker.isEmpty(roleId)) {
			return "";
		} else {
			Role role = RoleFactory.getRole(roleId);
			unit.setTitle((new StringBuilder(String
					.valueOf(((UnitComponent) unit).getTitle()))).append(" - ")
					.append(role.getName()).append("(").append(roleId).append(
							")").toString());
			return unit.write(ac);
		}
	}
}
